package com.xgkj.diyiketang.fragment;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.easemob.chat.EMChatManager;
import com.umeng.analytics.MobclickAgent;

import com.xgkj.diyiketang.EatShowApp;
import com.xgkj.diyiketang.activity.BaseActivity;
import com.xgkj.diyiketang.activity.CreateQuestionActivity;
import com.xgkj.diyiketang.activity.GuoxueSchoolActivity;
import com.xgkj.diyiketang.activity.InvideVipActivity;
import com.xgkj.diyiketang.activity.LoginActivity;
import com.xgkj.diyiketang.activity.MallActivity;
import com.xgkj.diyiketang.activity.MyChuTiActivity;
import com.xgkj.diyiketang.activity.MyFansListActivity;
import com.xgkj.diyiketang.activity.MyFlowerActivity;

import com.xgkj.diyiketang.activity.MyOrderActivity;
import com.xgkj.diyiketang.activity.MyRiJiActivity;
import com.xgkj.diyiketang.activity.MySheTuanActivity;
import com.xgkj.diyiketang.activity.MyZhiboListActivity;
import com.xgkj.diyiketang.activity.MyzhanghuTwoActivity;
import com.xgkj.diyiketang.activity.OpenVipActivity;
import com.xgkj.diyiketang.activity.ParentsActivity;
import com.xgkj.diyiketang.activity.SettingActivity;
import com.xgkj.diyiketang.activity.WebViewActivity;
import com.xgkj.diyiketang.activity.ZhangHuYueActivity;
import com.xgkj.diyiketang.activity.ZhuanyunMoneyActivity;
import com.xgkj.diyiketang.activity.ZhuanyunOrderActivity;
import com.xgkj.diyiketang.activity.ZhunyunSchoolActivity;
import com.xgkj.diyiketang.http.engine.ShowToastTaskEventListener;
import com.xgkj.diyiketang.hxsdk.DemoDBManager;
import com.xgkj.diyiketang.task.GetUserDetailTask;
import com.xgkj.diyiketang.task.LogoutTask;
import com.xgkj.diyiketang.R;
import com.xgkj.diyiketang.activity.MyAttentionActivity;
import com.xgkj.diyiketang.activity.MyShouCangListActivity;
import com.xgkj.diyiketang.activity.UserInfoActivity;
import com.xgkj.diyiketang.data.EatShowUserInfo;
import com.xgkj.diyiketang.util.DialogUtil;
import com.xgkj.diyiketang.util.EatShowSetting;
import com.xgkj.diyiketang.util.ImageCache;
import com.xgkj.diyiketang.util.PalLog;
import com.xgkj.diyiketang.util.ToastUtil;
import com.xgkj.diyiketang.util.ViewUtil;
import com.xgkj.diyiketang.yizhibo.Constants;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;

/**
 * Created by Administrater on 2015/12/8.
 */
public class MyFragment extends BaseFragment implements View.OnClickListener {
    private static final String TAG = MyFragment.class.getSimpleName();
    private Context mContext;
    private RelativeLayout myInfoLayout;
    //    private RelativeLayout myBalanceLayout;
//    private RelativeLayout rechargeLayout;
    private RelativeLayout myAttentionLayout;

    private RelativeLayout applyToAnchorLayout;
    private RelativeLayout myShouCangLayout;
    //    private RelativeLayout myShangChuan;
    private RelativeLayout myZhanghu;
    //    private RelativeLayout myHuoDong;
    private RelativeLayout settingLayout;
    //private RelativeLayout myHuoDongGeRen;
    /*vip yaoqing*/

    private RelativeLayout inviteVipLayout;
    private static final String CACHE_FILE = "diyiketang/cache";
    private static final String APK_FILE = "diyiketang/apk";
    private static final String IMG_FILE = "diyiketang/img";
    private static final String ROOT_PHONE = "tel:4009008835";
    private EatShowUserInfo userInfo;
    private ImageView headImage;
    private TextView nickNameText;
    private TextView sigatureText;
    //    private TextView exitBtn;
//    private RelativeLayout myXiangcheLayout;
//    private RelativeLayout myOrderLayout;
    private View view;
    private RelativeLayout timuLayout;
    private RelativeLayout myshetuanLayout;
    private RelativeLayout myliwuLayout;
    private RelativeLayout myrijiLayout;
    private RelativeLayout liwuduihuanLayout,guoxue_school;
    private RelativeLayout myParentLayout, zhuanun_school;
    private RelativeLayout myVipLayout;
    private RelativeLayout myFlowerLayout;
    private RelativeLayout inviteFriendLayout;
    private ImageView parentDivider;
    private TextView shetuanDivider;
    private ImageView vipImage;
    private RelativeLayout myOrderLayout;
    private RelativeLayout myZhiboLayout,parent_school;
    private LinearLayout zhibo_ll,guanzhu_ll,fans_ll;
    private TextView myzhiboDivider;
    private ImageView shenfenImage;
    private RelativeLayout timuglLayout;
    private int detailTaskId = -1;
    private boolean isVip;
    private TextView zhanghuyue;
    private TextView xiaohua,zhibo_num,guanzhu_num,fans_num;
    private TextView dingdan;
    private boolean zhuanyun_boolean = false;
    private boolean parent_boolean = false;
    private String zhuanyun_yuanzhang;
    private String zhuanyun_zhuren;
    private String zhuanyun_daoshi;
    private String zhuanyun_xueyuan;
    private String fumu_yuanzhang;
    private String fumu_zhuren;
    private String fumu_daoshi;
    private String fumu_xueyuan;
    private int vipCode;
    private String minge;
    private String yz_minge;
    private String zr_minge;
    private String ds_minge;
    private String xy_minge;
    private String unLockFlower;
    private String haveBindPay;
    private String z_yz_minge;
    private String z_zr_minge;
    private String z_ds_minge;
    private String z_xy_minge;
    private String p_yz_minge;
    private String p_zr_minge;
    private String p_ds_minge;
    private String p_xy_minge;
    private String decode;


    @Override
    protected int getContentViewId() {
        return 0;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.myfragment, null);
            mContext = getActivity();
            initView(view);
        }

        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }
        return view;
    }


    private void initView(View view) {
        myInfoLayout = (RelativeLayout) view.findViewById(R.id.my_info);
        myInfoLayout.setOnClickListener(this);
        zhibo_ll = (LinearLayout) view.findViewById(R.id.my_zhibo_ll);
        zhibo_ll.setOnClickListener(this);
        guanzhu_ll = (LinearLayout) view.findViewById(R.id.my_guanzhu_ll);
        guanzhu_ll.setOnClickListener(this);
        fans_ll = (LinearLayout) view.findViewById(R.id.my_fans_ll);
        fans_ll.setOnClickListener(this);
        zhibo_num = (TextView) view.findViewById(R.id.my_zhibo);
        guanzhu_num = (TextView) view.findViewById(R.id.my_guanzhu);
        fans_num = (TextView) view.findViewById(R.id.my_fans);
//        myBalanceLayout = (RelativeLayout) view.findViewById(R.id.mybalance_layout);
//        myBalanceLayout.setOnClickListener(this);
        zhuanun_school = (RelativeLayout) view.findViewById(R.id.my_zhuanyun_school_layout);
        zhuanun_school.setOnClickListener(this);
//        myAttentionLayout = (RelativeLayout) view.findViewById(R.id.myattention_layout);
//        myAttentionLayout.setOnClickListener(this);
        parent_school = (RelativeLayout) view.findViewById(R.id.my_parent_school_layout);
        parent_school.setOnClickListener(this);
        myFlowerLayout = (RelativeLayout) view.findViewById(R.id.myflower_layout);
        myFlowerLayout.setOnClickListener(this);
        guoxue_school = (RelativeLayout) view.findViewById(R.id.my_guoxue_layout);
        guoxue_school.setOnClickListener(this);
//        applyToAnchorLayout = (RelativeLayout) view.findViewById(R.id.apply_to_anchor_layout);
//        applyToAnchorLayout.setOnClickListener(this);

//        myshetuanLayout = (RelativeLayout) view.findViewById(R.id.myshetuan_layout);
//        myshetuanLayout.setOnClickListener(this);

        myliwuLayout = (RelativeLayout) view.findViewById(R.id.mygift_layout);
        myliwuLayout.setOnClickListener(this);

//        myrijiLayout = (RelativeLayout) view.findViewById(R.id.myriji_layout);
//        myrijiLayout.setOnClickListener(this);

//        liwuduihuanLayout = (RelativeLayout) view.findViewById(R.id.my_duihuanliwu);
//        liwuduihuanLayout.setOnClickListener(this);

//        myParentLayout = (RelativeLayout) view.findViewById(R.id.my_parent_layout);
//        myParentLayout.setOnClickListener(this);

        myShouCangLayout = (RelativeLayout) view.findViewById(R.id.my_shoucang);
        myShouCangLayout.setOnClickListener(this);
//        myShangChuan = (RelativeLayout) view.findViewById(R.id.my_shangchuan);
//        myShangChuan.setOnClickListener(this);
        myZhanghu = (RelativeLayout) view.findViewById(R.id.myzhanghu_layout);
        myZhanghu.setOnClickListener(this);
//        myXiangcheLayout = (RelativeLayout) view.findViewById(R.id.myxiangce_layout);
//        myXiangcheLayout.setOnClickListener(this);
        settingLayout = (RelativeLayout) view.findViewById(R.id.setting_layout);
        settingLayout.setOnClickListener(this);
        /*vip invite*/
        inviteVipLayout = (RelativeLayout) view.findViewById(R.id.invitevip_layout);
        inviteVipLayout.setOnClickListener(this);
        headImage = (ImageView) view.findViewById(R.id.head_img);
        nickNameText = (TextView) view.findViewById(R.id.nickname);
        sigatureText = (TextView) view.findViewById(R.id.person_signature);
//        timuLayout = (RelativeLayout) view.findViewById(R.id.tuijiancai_manager_layout);
//        timuLayout.setOnClickListener(this);

        myVipLayout = (RelativeLayout) view.findViewById(R.id.vip_layout);
        myVipLayout.setOnClickListener(this);
        inviteFriendLayout = (RelativeLayout) view.findViewById(R.id.invitefriend_layout);
        inviteFriendLayout.setOnClickListener(this);
//        parentDivider = (ImageView) view.findViewById(R.id.parent_divider);
//        shetuanDivider = (TextView) view.findViewById(R.id.shetuan_divider);
        vipImage = (ImageView) view.findViewById(R.id.isvip);
        myOrderLayout = (RelativeLayout) view.findViewById(R.id.mydingdan_layout);
        myOrderLayout.setOnClickListener(this);
//        myZhiboLayout = (RelativeLayout) view.findViewById(R.id.myzhibo_layout);
//        myZhiboLayout.setOnClickListener(this);
        timuglLayout = (RelativeLayout) view.findViewById(R.id.timu_manager_layout);
        timuglLayout.setOnClickListener(this);
        shenfenImage = (ImageView) view.findViewById(R.id.shenfen);
        zhanghuyue = (TextView) view.findViewById(R.id.zhanghuyue);
        xiaohua = (TextView) view.findViewById(R.id.xiaohua);
        dingdan = (TextView) view.findViewById(R.id.dingdan);
//        updateUserInfo();
        getUserDetail();
    }

    private void getUserDetail() {
        GetUserDetailTask task = new GetUserDetailTask();
        task.addListener(new MyListener(mContext));
        detailTaskId = getEatShowApp().getTaskManager().addTask(task);
    }

    class MyListener extends ShowToastTaskEventListener {
        public MyListener(Context context) {
            super(context);
        }

        @Override
        public void handleTaskCompleted(int taskId, int result, Object data) {
            super.handleTaskCompleted(taskId, result, data);
            if (detailTaskId == taskId)
                if (data != null) {
                    userInfo = (EatShowUserInfo) data;
                    Log.e("userinfo", "" + userInfo.toString());
                    if (userInfo != null) {
                        String head_url = userInfo.getUserLogo();
                        vipCode = userInfo.getVipCode();
                        unLockFlower = userInfo.getUnLockFlower();
                        haveBindPay = userInfo.getHaveBindPay();
                        if (!TextUtils.isEmpty(userInfo.getLiveCount())){
                            String liveCount = userInfo.getLiveCount();
                            zhibo_num.setText(liveCount);
                        }
                        if (!TextUtils.isEmpty(userInfo.getFans())){
                            String fans = userInfo.getFans();
                            fans_num.setText(fans);
                        }
                        if (!TextUtils.isEmpty(userInfo.getColleCount())){
                            String colleCount = userInfo.getColleCount();
                            guanzhu_num.setText(colleCount);
                        }

                        if (haveBindPay!=null){
                            EatShowApp.getACache().put(Constants.HAVE_BIND_PAY,haveBindPay);
                        }
                        if (userInfo.getList() != null && userInfo.getList().size() > 0) {
                            for (int i = 0; i < userInfo.getList().size(); i++) {
                                String xueyuan = userInfo.getList().get(i).xueyuan;
                                if (xueyuan.equals("3d9513eb1b674af98de226b315765e3f")) {
                                    if (userInfo.getList().get(i).shenfen.equals("0")) {
                                        z_yz_minge = userInfo.getList().get(i).minge;
                                    } else if (userInfo.getList().get(i).shenfen.equals("1")) {
                                        z_zr_minge = userInfo.getList().get(i).minge;
                                    } else if (userInfo.getList().get(i).shenfen.equals("2")) {
                                        z_ds_minge = userInfo.getList().get(i).minge;
                                    } else if (userInfo.getList().get(i).shenfen.equals("3")) {
                                        z_xy_minge = userInfo.getList().get(i).minge;
                                    }
                                    //父母大学
                                } else if (xueyuan.equals("2737f7a418bf41c998728e6a0f9f253d")) {
                                    if (userInfo.getList().get(i).shenfen.equals("0")) {
                                        p_yz_minge = userInfo.getList().get(i).minge;
                                    } else if (userInfo.getList().get(i).shenfen.equals("1")) {
                                        p_zr_minge = userInfo.getList().get(i).minge;
                                    } else if (userInfo.getList().get(i).shenfen.equals("2")) {
                                        p_ds_minge = userInfo.getList().get(i).minge;
                                    } else if (userInfo.getList().get(i).shenfen.equals("3")) {
                                        p_xy_minge = userInfo.getList().get(i).minge;
                                    }
                                }
                            }
                        }
                        if (userInfo.getIdentityList() != null && userInfo.getIdentityList().size() > 0) {

                            for (int i = 0; i < userInfo.getIdentityList().size(); i++) {
                                String xueyuan = userInfo.getIdentityList().get(i).xueyuan;
                                //转运
                                if (xueyuan.equals("3d9513eb1b674af98de226b315765e3f")) {
                                    String shenfen = userInfo.getIdentityList().get(i).shenfen;
                                    zhuanyun_boolean = true;
                                    if (shenfen.equals("0")) {
                                        zhuanyun_yuanzhang = "院长";
                                    } else if (shenfen.equals("1")) {
                                        zhuanyun_zhuren = "主任";
                                    } else if (shenfen.equals("2")) {
                                        zhuanyun_daoshi = "导师";
                                    } else if (shenfen.equals("3")) {
                                        zhuanyun_xueyuan = "学员";
                                    }
                                    //父母大学
                                } else if (xueyuan.equals("2737f7a418bf41c998728e6a0f9f253d")) {
                                    String shenfen = userInfo.getIdentityList().get(i).shenfen;
                                    parent_boolean = true;
                                    if (shenfen.equals("0")) {
                                        fumu_yuanzhang = "院长";
                                    } else if (shenfen.equals("1")) {
                                        fumu_zhuren = "主任";
                                    } else if (shenfen.equals("2")) {
                                        fumu_daoshi = "导师";
                                    } else if (shenfen.equals("3")) {
                                        fumu_xueyuan = "学员";
                                    }
                                }
                            }
                        }
                        if (head_url != null && head_url.length() > 0) {
                            ImageCache.getInstance(mContext).loadBitmapToView(headImage, head_url, new ViewUtil.Size(ViewUtil.dip2px(mContext, 85), ViewUtil.dip2px(mContext, 85)));
                        }

                        try {
                            if (!TextUtils.isEmpty(userInfo.getNickName())) {
                                decode = URLDecoder.decode(userInfo.getNickName(), "utf-8");
                                nickNameText.setText(URLDecoder.decode(userInfo.getNickName(), "utf-8"));
                            }

                            if (!TextUtils.isEmpty(userInfo.getUserSign())) {
                                sigatureText.setText(URLDecoder.decode(userInfo.getUserSign(), "utf-8"));
                            }
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                        zhanghuyue.setText(userInfo.getUnLockFlower());
                        xiaohua.setText(userInfo.getUnLockFlower());
                        dingdan.setText(userInfo.getOrderCount());
                        if (userInfo.isVip() == 1) {
                            vipImage.setVisibility(View.VISIBLE);
                            vipImage.setImageResource(R.drawable.vip1);
                            inviteVipLayout.setVisibility(View.VISIBLE);
                            isVip = true;
                        }
                        if (userInfo.isVip() == 2) {
                            vipImage.setVisibility(View.VISIBLE);
                            vipImage.setImageResource(R.drawable.vip2);
                            inviteVipLayout.setVisibility(View.VISIBLE);
                            isVip = true;
                        }
                        if (userInfo.isVip() == 3) {
                            vipImage.setVisibility(View.VISIBLE);
                            vipImage.setImageResource(R.drawable.vip3);
                            inviteVipLayout.setVisibility(View.VISIBLE);
                            isVip = true;
                        }
                        if (userInfo.isVip() == 4) {
                            vipImage.setVisibility(View.VISIBLE);
                            vipImage.setImageResource(R.drawable.vip4);
                            inviteVipLayout.setVisibility(View.VISIBLE);
                            isVip = true;
                        }
                        if (userInfo.isVip() == 5) {
                            vipImage.setVisibility(View.VISIBLE);
                            vipImage.setImageResource(R.drawable.vip5);
                            inviteVipLayout.setVisibility(View.VISIBLE);
                            isVip = true;
                        } else if (userInfo.isVip() == 0) {
                            isVip = false;
                            vipImage.setVisibility(View.GONE);
                        }
                        if (userInfo.getUserType() == 0) {
                            shenfenImage.setImageResource(R.drawable.xuesheng);
//                            applyToAnchorLayout.setVisibility(View.VISIBLE);
//                            timuLayout.setVisibility(View.GONE);
//                            myParentLayout.setVisibility(View.VISIBLE);
//                            parentDivider.setVisibility(View.VISIBLE);
                            timuglLayout.setVisibility(View.GONE);
                        } else if (userInfo.getUserType() == 1) {
                            shenfenImage.setImageResource(R.drawable.laoshi);
//                            applyToAnchorLayout.setVisibility(View.GONE);
//                            timuLayout.setVisibility(View.VISIBLE);
//                            myParentLayout.setVisibility(View.GONE);
//                            parentDivider.setVisibility(View.GONE);
//                            myZhiboLayout.setVisibility(View.VISIBLE);
                            timuglLayout.setVisibility(View.VISIBLE);
                        } else if (userInfo.getUserType() == 2) {
                            shenfenImage.setImageResource(R.drawable.jiazhang);
                        } else if (userInfo.getUserType() == 3) {
                            shenfenImage.setImageResource(R.drawable.daidinglaoshi);
                        }

                    }

                }
        }

        @Override
        public void handleTaskError(int taskId, int errorCode, String errorMsg) {
            super.handleTaskError(taskId, errorCode, errorMsg);
        }

        @Override
        public void handleTaskMessage(int taskId, Object data) {
            super.handleTaskMessage(taskId, data);
        }
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            getUserDetail();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        getUserDetail();
        MobclickAgent.onPageStart("MyFragment");
    }

    private void updateUserInfo() {
        userInfo = getEatShowApp().getmUserInfo();
        if (userInfo != null) {
            String head_url = userInfo.getUserLogo();
            if (head_url != null && head_url.length() > 0) {
                ImageCache.getInstance(mContext).loadBitmapToView(headImage, head_url, new ViewUtil.Size(ViewUtil.dip2px(mContext, 85), ViewUtil.dip2px(mContext, 85)));
            }

            try {
                if (!TextUtils.isEmpty(userInfo.getNickName())) {
                    nickNameText.setText(URLDecoder.decode(userInfo.getNickName(), "utf-8"));
                }

                if (!TextUtils.isEmpty(userInfo.getUserSign())) {
                    sigatureText.setText(URLDecoder.decode(userInfo.getUserSign(), "utf-8"));
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            if (0 != userInfo.isVip()) {
                vipImage.setVisibility(View.VISIBLE);
            } else {
                vipImage.setVisibility(View.GONE);
            }

            if (userInfo.getUserType() == 0) {
                shenfenImage.setImageResource(R.drawable.xuesheng);
                applyToAnchorLayout.setVisibility(View.VISIBLE);
//                timuLayout.setVisibility(View.GONE);
//                myParentLayout.setVisibility(View.VISIBLE);
//                parentDivider.setVisibility(View.VISIBLE);
//                myshetuanLayout.setVisibility(View.VISIBLE);
//                shetuanDivider.setVisibility(View.VISIBLE)
//                myZhiboLayout.setVisibility(View.GONE);
//                myzhiboDivider.setVisibility(View.GONE);
                timuglLayout.setVisibility(View.GONE);
            } else if (userInfo.getUserType() == 1) {
                shenfenImage.setImageResource(R.drawable.laoshi);
                applyToAnchorLayout.setVisibility(View.GONE);
//                timuLayout.setVisibility(View.VISIBLE);
//                myParentLayout.setVisibility(View.GONE);
//                myshetuanLayout.setVisibility(View.GONE);
//                parentDivider.setVisibility(View.GONE);
//                shetuanDivider.setVisibility(View.GONE);
//                myZhiboLayout.setVisibility(View.VISIBLE);
//                myzhiboDivider.setVisibility(View.VISIBLE);
                timuglLayout.setVisibility(View.VISIBLE);
            } else if (userInfo.getUserType() == 2) {
                shenfenImage.setImageResource(R.drawable.jiazhang);
            }

        } else {
            PalLog.e(TAG, "go login");
//            Intent intent = new Intent(mContext, LoginActivity.class);
//            startActivity(intent);
        }
    }

    @Override
    public void onClick(View view) {
        //TODO 点击事件
        switch (view.getId()) {
            case R.id.my_info:
                Intent userInfo_intent = new Intent(mContext, UserInfoActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("youeryuan", userInfo.getYoueryuan());
                bundle.putString("xiaoxue", userInfo.getXiaoxue());
                bundle.putString("chuzhong", userInfo.getChuzhong());
                bundle.putString("gaozhong", userInfo.getGaozhong());
                bundle.putString("daxue", userInfo.getDaxue());
                bundle.putString("shuoshi", userInfo.getShuoshi());
                bundle.putString("boshi", userInfo.getBoshi());
                bundle.putString("work", userInfo.getWork());
                bundle.putString("area", userInfo.getArea());
                userInfo_intent.putExtra("school", bundle);
                startActivity(userInfo_intent);
                break;
//            case R.id.myattention_layout:
//                Intent myattention_intent = new Intent(mContext, MyAttentionActivity.class);
//                startActivity(myattention_intent);
//                break;
            case R.id.my_zhuanyun_school_layout:
//                if (zhuanyun_boolean) {
                    Intent zhaunyun_intent = new Intent(mContext, ZhuanyunMoneyActivity.class);
                zhaunyun_intent.putExtra("type","zhuanyun");
                zhaunyun_intent.putExtra("zhuanyun_yz", zhuanyun_yuanzhang);
                zhaunyun_intent.putExtra("zhuanyun_zr", zhuanyun_zhuren);
                zhaunyun_intent.putExtra("zhuanyun_ds", zhuanyun_daoshi);
                zhaunyun_intent.putExtra("zhuanyun_xy", zhuanyun_xueyuan);
                zhaunyun_intent.putExtra("vipCode", vipCode);
                zhaunyun_intent.putExtra("minge_yz", z_yz_minge);
                zhaunyun_intent.putExtra("minge_zr", z_zr_minge);
                zhaunyun_intent.putExtra("minge_ds", z_ds_minge);
                zhaunyun_intent.putExtra("minge_xy", z_xy_minge);
                    startActivity(zhaunyun_intent);
//                } else {
//                    Intent intent = new Intent(mContext, ZhunyunSchoolActivity.class);
//                    intent.putExtra("type","zhuanyun");
//                    startActivity(intent);
//                }
                break;
            case R.id.my_parent_school_layout:
//                if (parent_boolean) {
                    Intent intent = new Intent(mContext, ZhuanyunMoneyActivity.class);
                    intent.putExtra("type","parent");
                    intent.putExtra("zhuanyun_yz", fumu_yuanzhang);
                    intent.putExtra("zhuanyun_zr", fumu_zhuren);
                    intent.putExtra("zhuanyun_ds", fumu_daoshi);
                    intent.putExtra("zhuanyun_xy", fumu_xueyuan);
                    intent.putExtra("vipCode", vipCode);
                    intent.putExtra("minge_yz", p_yz_minge);
                    intent.putExtra("minge_zr", p_zr_minge);
                    intent.putExtra("minge_ds", p_ds_minge);
                    intent.putExtra("minge_xy", p_xy_minge);
                    startActivity(intent);
//                } else {
//                    Intent intent = new Intent(mContext, ZhunyunSchoolActivity.class);
//                    intent.putExtra("type","parent");
//                    startActivity(intent);
//                }
                break;
//            case R.id.apply_to_anchor_layout:
//                showApplyAnchorDialog();
//                break;
            case R.id.my_zhibo_ll:
                Intent zhibo_intent = new Intent(mContext, MyZhiboListActivity.class);
                zhibo_intent.putExtra("type","my_zhibo");
                startActivity(zhibo_intent);
                break;
            case R.id.my_guanzhu_ll:
                Intent attention_intent = new Intent(mContext, MyAttentionActivity.class);
                startActivity(attention_intent);
                break;
            case R.id.my_fans_ll:
                Intent fans_intent = new Intent(mContext, MyFansListActivity.class);
                startActivity(fans_intent);
                break;
            case R.id.my_shoucang:
                Intent myshoucangIntent = new Intent(mContext, ShouCangListActivity.class);
                startActivity(myshoucangIntent);
                break;
            case R.id.myzhanghu_layout:
                Intent zhanghuIt = new Intent(mContext, MyzhanghuTwoActivity.class);//new Intent(mContext, MyZhangHuActivity.class);
                if (unLockFlower!=null){
                    zhanghuIt.putExtra("zongzochan",unLockFlower);
                }
                if (haveBindPay!=null){
                    zhanghuIt.putExtra("haveBindPay",haveBindPay);
                }
                startActivity(zhanghuIt);
                break;

            case R.id.setting_layout:
                Intent setting_intent = new Intent(mContext, SettingActivity.class);
                startActivity(setting_intent);
                break;

//            case R.id.tuijiancai_manager_layout:
//                Intent tuijiancai_intent = new Intent(mContext, CreateQuestionActivity.class);
//                startActivity(tuijiancai_intent);
//                break;

            case R.id.mygift_layout:

                break;

//            case R.id.myriji_layout:
//                Intent rintent = new Intent(mContext, MyRiJiActivity.class);
//                startActivity(rintent);
//                break;

//            case R.id.my_duihuanliwu:
//                Intent mallIntent = new Intent(mContext, MallActivity.class);
//                startActivity(mallIntent);
//                break;

//            case R.id.my_parent_layout:
//                Intent pintent = new Intent(mContext, ParentsActivity.class);
//                startActivity(pintent);
//                break;

            case R.id.vip_layout:
                Intent vIntent = new Intent(mContext, OpenVipActivity.class);
                if (isVip) {
                    vIntent.putExtra("isVip", true);
                } else {
                    vIntent.putExtra("isVip", false);
                }
                startActivity(vIntent);
                break;
            case R.id.my_guoxue_layout:
                Intent flowe_intent = new Intent(mContext, GuoxueSchoolActivity.class);
                flowe_intent.putExtra("nickname",decode);
                startActivity(flowe_intent);
                break;
            case R.id.myflower_layout:
                Intent flower_intent = new Intent(mContext, MyFlowerActivity.class);
                startActivity(flower_intent);
                break;
            case R.id.invitefriend_layout:
//                Intent invite_intent = WebViewActivity.getIntent(mContext, "http://app.sjmingze.com/invite_friend/invite_friend.html");
                Intent intent_yaoqing = new Intent(mContext, ZhuanyunOrderActivity.class);
                intent_yaoqing.putExtra("type","yaoqing");
                startActivity(intent_yaoqing);
                break;
            case R.id.invitevip_layout:

               /* Intent invite_vip_intent = WebViewActivity.getIntent(mContext, " http://115.28.236.67:8099/classroom/shareVip.html?vipCode="++"&device=android");
                startActivity(invite_vip_intent);*/
                Intent invite_vip_intent = new Intent(mContext, InvideVipActivity.class);
                //invite_vip_intent.putExtra("vipcode","");
                invite_vip_intent.putExtra("VIPCODE", userInfo.getVipCode());
                Log.e("myfragment:", userInfo.getVipCode() + "::");
                //ToastUtil.showMessage(mContext,userInfo.getVipCode());
                startActivity(invite_vip_intent);
                break;
            case R.id.mydingdan_layout:
                Intent oInent = new Intent(mContext, MyOrderActivity.class);
                startActivity(oInent);
                break;
//            case R.id.myzhibo_layout:
//                Intent myzhibo_intent = new Intent(mContext, MyZhiboListActivity.class);
//                startActivity(myzhibo_intent);
//                break;
            case R.id.timu_manager_layout:
                Intent glIntent = new Intent(mContext, MyChuTiActivity.class);
                startActivity(glIntent);
                break;

            default:
                break;
        }

    }

    private void showExitDialog() {
        DialogUtil.createDialog(mContext, -1, getString(R.string.prompt), getString(R.string.exit_app), getString(R.string.ok), getString(R.string.cancle), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                EatShowSetting.getInstance(mContext).setLoginName(null);
                EatShowSetting.getInstance(mContext).setLoginPsw(null);
                EatShowSetting.getInstance(mContext).setThirdNickname(null);
                EatShowSetting.getInstance(mContext).setThirdOpenid(null);
                EatShowSetting.getInstance(mContext).setThirdLogo(null);
//                getEatShowApp().exitApp();
                getEatShowApp().setmUserInfo(null);
                EMChatManager.getInstance().logout();
                DemoDBManager.getInstance().closeDB();
                doLogout();
                getActivity().finish();
                Intent intent = new Intent(mContext, LoginActivity.class);
                startActivity(intent);
            }
        }, null);
    }

    public static String getTotalCacheSize(Context context) throws Exception {

//        long cacheSize = getFolderSize(context.getCacheDir());
        File file = EatShowSetting.getInstance(context).getDataFolder(CACHE_FILE);
        File apkFile = EatShowSetting.getInstance(context).getDataFolder(APK_FILE);
        File imgFile = EatShowSetting.getInstance(context).getDataFolder(IMG_FILE);

        long cacheSize = getFolderSize(file);
        cacheSize += getFolderSize(apkFile);
        cacheSize += getFolderSize(imgFile);
        return getFormatSize(cacheSize);
    }

    public static String getFormatSize(double size) {
        double kiloByte = size / 1024;
        if (kiloByte < 1) {
            return "0K";
        }

        double megaByte = kiloByte / 1024;
        if (megaByte < 1) {
            BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
            return result1.setScale(2, BigDecimal.ROUND_HALF_UP)
                    .toPlainString() + "KB";
        }

        double gigaByte = megaByte / 1024;
        if (gigaByte < 1) {
            BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
            return result2.setScale(2, BigDecimal.ROUND_HALF_UP)
                    .toPlainString() + "MB";
        }

        double teraBytes = gigaByte / 1024;
        if (teraBytes < 1) {
            BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
            return result3.setScale(2, BigDecimal.ROUND_HALF_UP)
                    .toPlainString() + "GB";
        }
        BigDecimal result4 = new BigDecimal(teraBytes);
        return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()
                + "TB";
    }


    public static long getFolderSize(File file) throws Exception {
        long size = 0;
        try {
            File[] fileList = file.listFiles();
            for (int i = 0; i < fileList.length; i++) {
                // 如果下面还有文件
                if (fileList[i].isDirectory()) {
                    size = size + getFolderSize(fileList[i]);
                } else {
                    size = size + fileList[i].length();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return size;
    }


    private void doLogout() {
        LogoutTask task = new LogoutTask();
        getEatShowApp().getTaskManager().addTask(task);
    }

    private void showClearCacheDialog() {
        final ProgressDialog mProgress = DialogUtil.showProgressDialog(mContext, getString(R.string.do_clear_cache), false, null);
        File file = EatShowSetting.getInstance(mContext).getDataFolder(CACHE_FILE);
        if (file.exists()) {
            PalLog.e(TAG, file.getAbsolutePath() + "******" + file.getPath());
            delAllFile(file.getAbsolutePath());
        }

        File apkFile = EatShowSetting.getInstance(mContext).getDataFolder(APK_FILE);
        if (apkFile.exists()) {
            delAllFile(apkFile.getAbsolutePath());
        }

        File imgFile = EatShowSetting.getInstance(mContext).getDataFolder(IMG_FILE);
        if (imgFile.exists()) {
            delAllFile(imgFile.getAbsolutePath());
        }
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mProgress.dismiss();
                ToastUtil.showMessage(mContext, R.string.clear_cache_success);
//                mHuanCun.setText(null);
            }
        }, 2000);

    }

    public static void delAllFile(String path) {
        File file = new File(path);
        if (!file.exists()) {
            return;
        }
        if (!file.isDirectory()) {
            return;
        }
        String[] tempList = file.list();
        File temp = null;
        for (int i = 0; i < tempList.length; i++) {
            if (path.endsWith(File.separator)) {
                temp = new File(path + tempList[i]);
            } else {
                temp = new File(path + File.separator + tempList[i]);
            }
            if (temp.isFile()) {
                temp.delete();
            }
            if (temp.isDirectory()) {
                delAllFile(path + "/" + tempList[i]);
            }
        }
    }


    private Handler mHandler = new Handler();

    private void showApplyAnchorDialog() {
//        DialogUtil.createDialog(mContext, getString(R.string.prompt), getString(R.string.contacts_root), getString(R.string.ok), new DialogInterface.OnClickListener() {
//            @Override
//            public void onClick(DialogInterface dialog, int which) {
//                dialog.dismiss();
//                Intent call_intent = new Intent(Intent.ACTION_DIAL, Uri.parse(ROOT_PHONE));
//                startActivity(call_intent);
//            }
//        });

        DialogUtil.createDialog(mContext, -1, getString(R.string.prompt), getString(R.string.contacts_root), getString(R.string.ok), getString(R.string.cancle), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Intent call_intent = new Intent(Intent.ACTION_DIAL, Uri.parse(ROOT_PHONE));
                startActivity(call_intent);
            }
        }, null);
        //DialogUtil.showTextEntryDialog(mContext,null,getString(R.string.prompt),getString(R.string.contacts_root),getString(R.string.ok),getString(R.string.cancel),new sureListener ,new cancleListner);
    }


    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("MyFragment");
    }
//    private void initData() {
//
//    }

//    class MyListener extends ShowToastTaskEventListener {
//        public MyListener(Context context) {
//            super(context);
//        }
//
//        @Override
//        public void handleTaskCompleted(int taskId, int result, Object data) {
//            super.handleTaskCompleted(taskId, result, data);
//            if (data!=null){
//                userInfo = (EatShowUserInfo) data;
//                if (userInfo !=null){
//                    vipCode = userInfo.getVipCode();
//                    if (userInfo.getIdentityList()!=null){
//                        for (int i = 0; i < userInfo.getIdentityList().size(); i++) {
//                            String xueyuan = userInfo.getIdentityList().get(i).xueyuan;
//                            if (xueyuan.equals("3d9513eb1b674af98de226b315765e3f")){
//                                String shenfen = userInfo.getIdentityList().get(i).shenfen;
//                                if (shenfen.equals("0")){
//                                    zhuanyun_yuanzhang = "院长";
//                                }else if (shenfen.equals("1")){
//                                    zhuanyun_zhuren = "主任";
//                                }
//                                else if (shenfen.equals("2")){
//                                    zhuanyun_daoshi = "导师";
//                                }
//                                else if (shenfen.equals("3")){
//                                    zhuanyun_xueyuan = "学员";
//                                }
//                            }else if (xueyuan.equals("2737f7a418bf41c998728e6a0f9f253d")){
//                                String shenfen = userInfo.getIdentityList().get(i).shenfen;
//                                if (shenfen.equals("0")){
//                                    fumu_yuanzhang = "院长";
//                                }else if (shenfen.equals("1")){
//                                    fumu_zhuren = "主任";
//                                }
//                                else if (shenfen.equals("2")){
//                                    fumu_daoshi = "导师";
//                                }
//                                else if (shenfen.equals("3")){
//                                    fumu_xueyuan = "学员";
//                                }
//                            }
//                        }
//                    }
//
//                }
//            }
//        }
//
//        @Override
//        public void handleTaskError(int taskId, int errorCode, String errorMsg) {
//            super.handleTaskError(taskId, errorCode, errorMsg);
//        }
//
//        @Override
//        public void handleTaskMessage(int taskId, Object data) {
//            super.handleTaskMessage(taskId, data);
//        }
//    }
}
